package cn.tradewin.advisor.pages.security;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.Permissions;
import cn.tradewin.advisor.persist.services.AdvisorSecurityService;

public class PermBoard {

	@Inject
	private Messages messages;
	
	@Inject
	private BeanModelSource beanModelSource;
	
	@Property
	private BeanModel<Permissions> beanModel;
	
	@Inject
	private AdvisorSecurityService securityService;
	
	@Property
	private List<Permissions> perms;
	
	@Property
	private Permissions perm;
	
	@SetupRender
	void setupRender() throws DBException {
		beanModel = beanModelSource.createDisplayModel(Permissions.class, messages);
		beanModel.add("action", null);
		beanModel.include("permId", "permName", "permDesc", "action");
		beanModel.get("permId").sortable(false);
		beanModel.get("permName").sortable(true);
		beanModel.get("permDesc").sortable(false);
		beanModel.get("action").sortable(false);
	}	
	
	@OnEvent(EventConstants.PREPARE_FOR_RENDER)
	void prepareForRender() throws DBException {
		perms = securityService.listAllPerms();
	}
		
	public boolean isEmpty() {
		if (perms == null || perms.size() == 0)
			return true;
		return false;
	}
}
